<template>
	<view class="content">
		<view class="headerImg" @click="uploadImg">
			<image v-if="logoInfo.url!=''" :src="logoInfo.url"></image>
			<image v-if="logoInfo.url==''" src="http://rzkeji.oss-cn-shenzhen.aliyuncs.com/web/mingmei/smallicon/icon/default.png"></image>
			<view style="color: #666666;">点击更换图片</view>
		</view>
		<view class="catList">
			<catLabel dataType="text" text="姓名" v-model="realName" />
			<catLabel dataType="text" inputType="number" text="手机" v-model="phone" />
			<catLabel dataType="text" text="职位" v-model="position" />
			<catLabel dataType="text" text="邮箱" v-model="email" />
		</view>
		<button class="submit" @click="completeData">提交</button>
	</view>
</template>

<script>
	import catLabel from "@/components/cat-label/cat-label.vue";
	export default {
		data() {
			return {
				posterData: '',
				realName: '',
				phone:'',
				position: '',
				email: '',
				userId: '',
				logoInfo: {
					id: '',
					url: ''
				}
			}
		},
		components: {
			catLabel
		},
		onLoad(options) {
			if (options.userId) {
				this.userId = options.userId;
			}
			this.getMyselfBusinessCard();
		},
		methods: {
			async getMyselfBusinessCard() {
				//获取海报
				let userToken = uni.getStorageSync('userToken');
				let res = await this.$api.getMyselfBusinessCard({
					user_token: userToken,
					// uid: this.userId //分享人的id
				})
				if (res.data.level == 'success') {
					if(res.data.data.id){
							// this.posterData = res.data.data;
						this.realName = res.data.data.realname;
						this.userId = res.data.data.user_id;
						this.phone = res.data.data.phone_number;
						this.position = res.data.data.position;
						this.email = res.data.data.email;
						this.logoInfo.url = res.data.data.photo_url;
						this.logoInfo.id = res.data.data.card_img_id||res.data.data.photo_id;
					}
					
				}
			},
			async uploadImg() {
				//上传头像
				let res = await this.$currency.upLoadImage()
				let data = JSON.parse(res.data)
				if (data.level != 'success') {
					uni.showToast({
						title: data.message,
						icon: 'none'
					})
					return
				}
				this.logoInfo = {
					url: data.data.img_url,
					id: data.data.id
				}
			},
			async completeData(){
				//完善资料
				let userToken=uni.getStorageSync('userToken');
				let parmas={
					real_name:this.realName,
					phone_number:this.phone,
					position:this.position,
					email:this.email,
					user_token:userToken,
					photo_id: this.logoInfo.id
				}
				
				let res=await this.$api.completeData(parmas);
				uni.showToast({
					icon:'none',
					title:res.data.message
				})
				if(res.data.level=='success'){
					setTimeout(()=>{
						uni.navigateBack({
							delta:1
						})
					},2000)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.headerImg {
		text-align: center;
		padding: 30rpx;

		image {
			width: 200rpx;
			height: 200rpx;
			border-radius: 360rpx;
			overflow: hidden;
		}
	}

	.catList {
		padding-bottom: 100rpx;
	}

	.submit {
		position: fixed;
		bottom: 0rpx;
		width: 100%;
		background: linear-gradient(-135deg, #57D1E2 0%, #37AED6 100%);
		color: #fff
	}
</style>
